package com.cmc6.common.util.redis;

import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

public class MyRedisTemplate<T> extends RedisTemplate<String, T> {

    /**
     * Constructs a new <code>MyRedisTemplate</code> instance. {@link #setConnectionFactory(RedisConnectionFactory)}
     * and {@link #afterPropertiesSet()} still need to be called.
     */
    public MyRedisTemplate() {
        RedisSerializer<String> string = RedisSerializer.string();
        RedisSerializer<Object> json = RedisSerializer.json();
        setKeySerializer(string);
        setValueSerializer(json);
        setHashKeySerializer(string);
        setHashValueSerializer(json);
    }

    /**
     * Constructs a new <code>MyRedisTemplate</code> instance ready to be used.
     *
     * @param connectionFactory connection factory for creating new connections
     */
    public MyRedisTemplate(RedisConnectionFactory connectionFactory) {
        this();
        setConnectionFactory(connectionFactory);
        afterPropertiesSet();
    }

}
